<!DOCTYPE html>
<html>
<head>
    <title>注册页面</title>
    <meta charset="UTF-8">
    <script>
        function but() {
            let name = document.querySelector("#username").value;
            let phonenumber = document.querySelector("#tel").value;
            let pwd = document.querySelector("#password").value;
            let user = {"name": name, "phonenumber": phonenumber, "pwd": pwd};
            let json = JSON.stringify(user);
            console.log(json);
            let xhr = new XMLHttpRequest();
            xhr.open("post", "register.do");
            xhr.send(json);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4 && xhr.status === 200) {
                    document.querySelector("#ajax_span").innerHTML = xhr.responseText;
                }
            }
        }
    </script>
</head>
<body>
    <h3>点击链接访问数据库进行查询</h3>
    <br/>
    <a href="user.do">点击检测数据库是否连接（查询第一个条目）</a>
    <hr>
    <h3>注册一个用户（测试用）</h3>
    手机号：<input type="tel" id="tel"> <br>
    用户名：<input type="text" id="username"> <br>
    密 码 ：<input type="password" id="password">8-20位字母数字或特殊字符 <br>
    <input type="button" value="添加测试用户" onclick="but()">
    <span id="ajax_span">注册结果展示区</span>
    <hr>
    <a href="login.html">转跳到登录测试页面</a>
    <hr>
    <a href="dorm.html">转跳到宿舍信息页面</a>
</body>
</html>